import { post, _axios, postJson } from "@/util/http"

/**
 * 分页查询
 * @param  params 
 */
export const SelectPage = params => post(`/product/selectPage`, params)

/**
 * 新增
 * @param  params 
 */
export const InsertHandle = params => post(`/product/insert`, params)

/**
 * 更新
 * @param  params 
 */
export const UpdateHandle = params => post(`/product/update`, params)

/**
 * 删除
 * @param  params 
 */
export const DeleteHandle = params => post(`/product/delete`, params)

/**
 * 发布
 * @param  params 
 */
export const PublishHandle = params => post(`/product/publish`, params)

/**
 * 查询用户
 * @param  params 
 */
export const SelectUser = params => post(`/user/selectList`, params)



/**
 * 文件查询列表
 * @param  params 
 */
export const selectFiles = params => post(`/file/selectList`, params)

/**
 * 删除文件
 * @param  params 
 */
export const DeleteFile = params => post(`/file/delete`, params)

/**
 * 使用文件
 * @param  params 
 */
export const UsedFile = params => post(`/file/used`, params)


/**
 * 刷新文件
 * @param  params 
 */
export const refreshFile = params => post(`/file/refresh`, params)


/**
 * 上传附件
 *
 * @param {Object}
 * @return Result
 */
export const UploadFile = (params, callback) => _axios.post('/file/upload', params, {
  headers: { 'Content-Type': 'multipart/form-data' },
  onUploadProgress (progressEvent) {
    if(progressEvent.lengthComputable){
      //属性lengthComputable主要表明总共需要完成的工作量和已经完成的工作是否可以被测量
      //如果lengthComputable为false，就获取不到progressEvent.total和progressEvent.loaded
      callback(progressEvent);
    }
  }
})

/**
 * 查询配置
 * @param  params 
 */
export const SelectConfig = params => post(`/manager/config/get`, params)

/**
 * 保存配置
 * @param  params 
 */
export const SaveConfig = params => post(`/manager/config/save`, params)

/**
 * 排序
 * @param  params 
 */
export const SortHandle = params => postJson(`/product/sort`, params)

/**
 * 是否存在素材
 * @param  params 
 */
export const hasFile = params => post(`/file/hasFile`, params)
